package com.example.bigeventMaven.Detail;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by 10446 on 2017/9/9.
 */
@Service
public class DetailService {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public Detail getDetail(String id) {
        String sql = "SELECT  name,detail,YEAR (date) AS YEAR ,MONTH (date) as MONTH ,DAY(date) as DAY FROM bigevent WHERE id = "+id;
        List list =  (List<Detail>) jdbcTemplate.query(sql, new RowMapper() {
            @Override
            public Object mapRow(ResultSet resultSet, int i) throws SQLException {
                Detail obj = new Detail();
                obj.setDetail(resultSet.getString("detail"));
                obj.setHeader(resultSet.getString("name"));
                obj.setTime(resultSet.getString("YEAR")+"年"+resultSet.getString("MONTH")+"月"+resultSet.getString("DAY")+"日");
//                System.out.println(resultSet.getInt("id"));
                return obj;
            }

        });
        Detail detail = (Detail) list.get(0);
        return detail;
    }
}
